package cn.tedu.shoppingmall.mapper;

import cn.tedu.shoppingmall.vo.Commodity;
import cn.tedu.shoppingmall.vo.Images;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

//商品数据库增删改查操作
@Repository
public interface CommodityMapper {
    //增加商品
    @Insert("insert into commodity(name,intro,sum,salesnum,price,classId,url)" +
            " values(#{name},#{intro},#{sum},0,#{price},#{classId},#{url})")
    void insert(Commodity commodity);


    //根据id删除商品
    @Delete("delete from commodity where id=#{id}")
    void delete(int id);


    //修改商品信息name,intro,sum,salenum,price,classId,url
    @Update("update commodity set name=#{name},intro=#{intro},sum=#{sum},salesnum=#{salesnum},price=#{price},classId=#{classId},url=#{url} where id=#{id}")
    void update(Commodity commodity);
    //商品搜索次数增加  +1
    @Update("update commodity set searchnum=searchnum+1 where id=#{id}")
    Integer UpdateToCommoditySearchnumAdd(int id);
    //商品购买次数增加  +1
    @Update("update commodity set paynum=paynum+1 where id=#{id}")
    Integer UpdateToCommodityPaynumAdd(int id);
    //商品浏览次数增加  +1
    @Update("update commodity set shownum=shownum+1 where id=#{id}")
    Integer UpdateToCommodityShownumAdd(int id);
    //支付后 根据商品id把已售数量修改
    @Update("update commodity set salesnum=salesnum+#{num} where id=#{id}")
    void toShopping(int id,int num);




    //查询所有商品,并根据类别id正序排序
    @Select("select * from commodity order by classId asc")
    List<Commodity> select();
    //搜索商品id搜索单个商品信息
    @Select("select * from commodity where id=#{id}")
    Commodity SelectById(int id);
    //首页根据搜索框信息,模糊查询所匹配的内容和名字里包含信息的商品信息
    @Select("select * from commodity where name like '%${content}%' or intro like '%${content}%'")
    List<Commodity> SelectSearch(@Param("content") String content);
    //根据商品类别查询商品信息
    @Select("select * from commodity where classId=#{id}")
    List<Commodity> SelectByClsid(int id);
    //支付后 根据商品id查询库存和已售
    @Select("select sum,salesnum from commodity where id=#{id}")
    Commodity SelectToSum(int id);
    //查询图片集有没有comid
    @Select("select id from imgs where comid=#{comid}")
    Integer SelectToIdByComid(int comid);



}
